﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project
{
    public partial class GarageAdd : Form
    {
        public GarageAdd()
        {
            InitializeComponent();
        }


        private void Form4_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string numbering = this.textBoxNumbering.Text, IntPrice = this.textBoxInStoreagePrice.Text, outPrice = this.textBoxOutPrice.Text, number = this.textBoxNumber.Text, color = this.comboBoxColor.SelectedItem.ToString(), name = this.textBoxName.Text;int typeId=this.comboBox1.SelectedIndex+1;
            string sql = "INSERT INTO [dbo].[Garage]([CarName],[InStoreagePrice],[OutPrice],[CarTypeId],CarNumbering,Color,Number)VALUES('{0}','{1}','{2}',{3},'{4}','{5}',{6})";
            sql = string.Format(sql,name,IntPrice,outPrice,typeId,numbering,color,number);
            int re= DBHelper.ExecuteNonQuery(sql);
            if (re>0)
            {
                MessageBox.Show("添加成功");
            }
            
        }

        private void GarageAdd_Load(object sender, EventArgs e)
        {
            InitData();


        }
        public void InitData()
        {
            comboBoxColor.Items.Add("红色");
            comboBoxColor.Items.Add("白色");
            comboBoxColor.Items.Add("绿色");
            comboBoxColor.Items.Add("灰色");
            comboBoxColor.Items.Add("天蓝色");
            comboBoxColor.Items.Add("黄色");
            string sql = "select * from CarType";
            DataTable dt= DBHelper.GetTable(sql);
            foreach (DataRow item in dt.Rows)
            {
                this.comboBox1.Items.Add(item["TypeName"]);
            }
            this.comboBox1.SelectedIndex = 0;
        }
    }
}
